import axios from 'axios'
import { isString } from '.'

const API_URL = 'http://127.0.0.1:7001'

export function get(config) {
  const connectionId = sessionStorage.getItem('connectionId')
  const { url, params } = isString(config) ? { url: config } : config
  return axios.get(`${API_URL}${url}`, {
    params: {
      ...params,
      connectionId
    },
  })
}

export function post(config) {
  const connectionId = sessionStorage.getItem('connectionId')
  const { url, data, params } = isString(config) ? { url: config } : config
  return axios.post(`${API_URL}${url}`, data, {
    params: {
      ...params,
      connectionId
    },
  })
}